﻿create PROCEDURE Sync.SP_LoanExecutionInstallments_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanExecutionInstallmentID],
		g.[LoanExecutionID],g.[InstallmentDate],g.[OriginalInstallmentAmount],g.[InterestInstallmentAmount],g.[TotalInstallmentAmount],g.[PenaltyDays],g.[PenaltyAmount],g.[IsPaid],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanExecutionInstallments] g RIGHT JOIN Sync.LoanExecutionInstallments_Tracking t  
    ON t.LoanExecutionInstallmentID = g.LoanExecutionInstallmentID 
    join LoanExecution le on le.LoanExecutionID = g.LoanExecutionID
	join CustomerLoans cl
	on le.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END











